package SC;

import java.lang.reflect.*;
import java.lang.reflect.Method;
import java.util.Hashtable;

import javax.jws.Oneway;

/*
 * The ServiceConnector class invokes a selected method on a selected class
 * instance
 * The ServiceConnector can actually play not only its own (object ) role
 * As a good actor it can also play objects of any (existing) type 
 * If necessary the ServiceConnector loads a new class at run-time 
 * The ServiceConnector has a registry where it keeps ( and reuses ) all actors 
 * @author Jeff.Zhuk@JavaSchool.com 
 */


public class ServiceConnector {
	protected Object[] parameters;
	protected Object result;
	protected Method method;
	protected Object actingObject;
	
	protected actingClass = getClass();
	protected String actingClassName = actingClass.getName();
	protected String defaultServiceName;
	protected Hashtable actingObjects = new Hashtable();
	// repository of objects
	
	public ServiceConnector(){}
	/**
	 * The constructor creates an object of a requested class
	 * If a requested class name is "ServiceConnector"  , there is nothing 
	 * to do .
	 * In this case the actingObject is "this"
	 * @param className
	 */
	public ServiceConnector(String className){
		// include the package name in the className to increase the efficiency.
		defaultServiceName = className;
	}
	
	/**
	 * The act() method provides a unified way to find a requested method 
	 * and invokes the method on previously defined object .
	 * There is a different version of the method for J2ME implementation .
	 * @param methodName
	 * @param paremeters 
	 * @return result  
	 */
	public Object act(String methodName , Object[] parameters){
		return act(actingClassName , methodName, parameters);
	}
	
	/**
	 * The act() method provides a unified way to find a requested method 
	 * and invokes the method on previously defined object .
	 * This version is a convenience method for a common case when parameters passed via a hash table
	 * @param className
	 * @param methodName
	 * @param tables of parameters 
	 * @return result  
	 */
	public Object act(String className , String methodName ,Hashtable table){
		Object[] objects = new Object[1];
		objects[0] = table;
		return act(actingClassName , methodName , objects);		
	}
	
	public Object act(String className , String methodName , Object[] parameters){
		try{
			changeActingClass(className);
			Class[] classes = null;
			if(parameters != null){
				classes = new Class[parameters.length];
				for(int i = 0 ; i < parameters.length;  i++){
					classes[i] = parameters[i].getClass();
					
				}
			}
			method = actingClass.getMethod()
			
		}
	}

	
	
	

}
